// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package conf

const (
	DefaultElasticLoggerAddresses = "http://127.0.0.1:9200"
	DefaultElasticLoggerIndex     = "log-2006.01.02"
	DefaultElasticLoggerIndexType = "_doc"
	DefaultElasticLoggerTimeout   = 5
)

// ElasticAdapterConfig
// is a component for elasticsearch.
type ElasticAdapterConfig struct {
	// Addresses
	// is elasticsearch clusters address.
	//
	//   Example:
	//     - http://127.0.0.1:9200
	Addresses []string `yaml:"addresses"`

	// Index
	// name of elasticsearch indices.
	//
	//   Default: log-2006.01.02
	Index string `yaml:"index"`

	// IndexType
	// type of elasticsearch indices if supported.
	//
	//   Default: _doc
	IndexType string `yaml:"index-type"`

	// Timeout
	// durations of elasticsearch request.
	//
	//   Default: 5
	//   Unit: Second
	Timeout int `yaml:"timeout"`

	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

// +---------------------------------------------------------------------------+
// | Access methods                                                            |
// +---------------------------------------------------------------------------+

func (o *ElasticAdapterConfig) init() {
	if len(o.Addresses) == 0 {
		o.Addresses = []string{DefaultElasticLoggerAddresses}
	}
	if o.Index == "" {
		o.Index = DefaultElasticLoggerIndex
	}
	if o.IndexType == "" {
		o.IndexType = DefaultElasticLoggerIndexType
	}
	if o.Timeout == 0 {
		o.Timeout = DefaultElasticLoggerTimeout
	}
}
